<template>
	<view>
		<view class="bg">
			<u-image width="150rpx" height="150rpx" :src="logo" style="margin-top: 300rpx;"></u-image>
			<view class="loginBox">
				<input v-model="form.username" label="用户名" placeholder="请输入学号/工号/管理员号" required>
				<input v-model="form.password" :password="true" label="密码" placeholder="请输入密码" required>
				
				<br>
				<br>
				<u-button size="medium" :loading="isLoading" type="primary" @tap="login">登录</u-button>
				<u-button size="medium" type="primary" @tap="torRegister">注册</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import logo from '@/static/logo.png';
	export default {
		data() {
			return {
				logo: logo,
				form: {
					username: "",
					password: ""
				},
				isLoading: false
			}
		},
		methods: {
			login() {
				const _this = this
				_this.isLoading = true;
				uni.request({
					method: "POST",    //这好像需要跳转
					data: _this.form,
					success({
						data
					}) {
						if (data.success) {
							uni.setStorageSync('token', data.result.token);
							uni.setStorageSync('userInfo',data.result.userInfo);
			/*这里是抄的 说是将登录信息以token的方式存在手机硬盘中
					    将用户信息存储在手机硬盘中		*/		
							uni.switchTab({
			//需要跳转			
							})
						} else {
							uni.showToast({
								title: data.message,
								duration: 666
							})
						}
					},
					fail(e) {
						uni.showToast({
							title: '请求失败' + e,
							duration: 666
						})
					},
					complete() {
						_this.isLoading = false;
					}
				})
			},
			toRegister() {
				uni.navigateTo({
		    //需要跳转			
				})
			}
		}
	}
</script>


<style scoped>
	.bg {
		width: 100vw;
		height: 100vh;
		background-image: url(../../static/loginBackground.png);
		background-size: cover;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.loginBox {
		width: 500rpx;
		height: 400rpx;
		background-color: rgba(255, 255, 255, .7);       /*半透明*/
		margin: auto;
		border-radius: 30rpx;
		padding: 30rpx;
		margin-top: 70rpx;
	}
</style>